<?php
namespace app\admin\controller;

use app\common\controller\Admin ; 

class Role extends Admin
{
    


    //控制器初始化
    public function _initialize()
    {
        parent::_initialize();
    }
    /**
     * 组织管理 
     */
    public function index()
    {

        $this->setMeta('系统管理|组织管理');
        return view('index');
    }

    /**
     * zNodes
     */
    public function zNodes(){

        $Role = model('Role');
        // $zNodes = $Role->order('sort asc')->select();
        $zNodes = $Role->zNodes();
// print_r($zNodes);
        return json($zNodes);

    }

    /**
     * ajax 读取一条记录
     * @param  integer $id [description]
     * @return [json]           [description]
     */
    public function get( $id = 0 ){
        //$this->requestInfo();
        if( ! $this->request->isAjax() ){
            return 'not ajax!!!' ;
        }

        $Role = model('Role');
        $rs = $Role->one($id);
        return json($rs);

    }

    /**
     * 添加 or  修改
     * @return [type]           [description]
     */
    public function save( ){

        if(!IS_AJAX){ return 'not ajax!!!' ;}
        $Role = model('Role');

        if( false ===  $Role->change() ){
            return json(['ret'=> 1 , 'msg'=> $this->Dept -> getError() , 'data' => null ]); 
        }
        return json(['ret'=> 0 , 'msg'=> 'ok' , 'data' => null ]); 
    }


    /**
     * [删除 ajax]
     * @return [type] [description]
     */
    public function delete(){
            //if(!IS_AJAX){ return 'not ajax!!!' ;}
            $id = array_unique((array) input('post.id/a', 0));
            
            $Role = model('Role');
            $rs = $Role->del($id);
            return json(['ret'=> 0 , 'msg'=> 'ok' , 'data' => null ]); 

    }









    


}
